package com.wzx.user.business.shop.controller;

import com.wzx.common.core.controller.AbstractCoreController;
import com.wzx.common.pojo.resp.Result;
import com.wzx.user.pojo.shop.dto.ReleaseDynamicDto;
import com.wzx.user.pojo.shop.pojo.ReleaseDynamic;

import com.wzx.user.pojo.shop.vo.PlaceAnOrderVo;
import com.wzx.user.pojo.shop.vo.QueryReleaseByPage;
import com.wzx.user.pojo.shop.vo.ReleaseDynamicVo;
import com.wzx.user.business.shop.service.ReleaseDynamicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author wzx
 * @version 1.0
 * @date 2023/2/16 - 19:07
 * @description 标题
 */
@Api(tags = "发布信息")
@RestController
@RequestMapping("/releaseDynamic")
public class ReleaseDynamicController extends AbstractCoreController<ReleaseDynamic> {

    @Autowired
    private ReleaseDynamicService releaseDynamicService;

    @Autowired
    protected ReleaseDynamicController(ReleaseDynamicService releaseDynamicService) {
        super(releaseDynamicService);
        this.releaseDynamicService = releaseDynamicService;
    }

    @PostMapping("/queryByTypePage")
    @ApiOperation(value = "根据类型或是状态条件查询")
    public Result queryByTypePage(@RequestBody QueryReleaseByPage queryReleaseByPage) throws Exception {
        return releaseDynamicService.queryByTypePage(queryReleaseByPage);
    }

    @PostMapping("/queryByOrder")
    @ApiOperation(value = "查询自己的订单，根据服务类型")
    public Result<List<ReleaseDynamicDto>> queryByOrder(@RequestBody QueryReleaseByPage queryReleaseByPage) throws Exception {
        List<ReleaseDynamicDto> lists = releaseDynamicService.queryByOrder(queryReleaseByPage);
        return Result.ok(lists);
    }

    @GetMapping("/removeRelease")
    @ApiOperation(value = "批量删除")
    public Result removeRelease(String ids) throws Exception {
        String[] split = ids.split(",");
        List<String> dayList = new ArrayList<String>(Arrays.asList(split));
        releaseDynamicService.removeByIds(dayList);
        //releaseDynamicService.removeRelease(ids);
        return Result.ok();
    }

    @GetMapping("/removeRleaseById")
    @ApiOperation(value = "根据id删除")
    public Result removeRleaseById(Integer id) throws Exception {
        releaseDynamicService.removeById(id);
        //releaseDynamicService.removeRelease(ids);
        return Result.ok();
    }

    @PostMapping("/placeAnOrder")
    @ApiOperation(value = "下单")
    public Result placeAnOrder(@RequestBody PlaceAnOrderVo placeAnOrderVo) throws Exception {
        releaseDynamicService.placeAnOrder(placeAnOrderVo);
        return Result.ok();
    }

    @PostMapping("/placeAnOrderByAmount")
    @ApiOperation(value = "余额下单")
    public Result placeAnOrderByAmount(@RequestBody PlaceAnOrderVo placeAnOrderVo) throws Exception {
        releaseDynamicService.placeAnOrderByAmount(placeAnOrderVo);
        return Result.ok();
    }

    @GetMapping("/cancelOrder")
    @ApiOperation(value = "取消下单")
    public Result cancelOrder(Integer releaseDynamicId) throws Exception {
        releaseDynamicService.cancelOrder(releaseDynamicId);
        return Result.ok();
    }

    @PostMapping("/changeState")
    @ApiOperation(value = "修改订单状态")
    public Result changeState(@RequestBody PlaceAnOrderVo placeAnOrderVo) throws Exception {
        releaseDynamicService.changeState(placeAnOrderVo);
        return Result.ok();
    }

    @GetMapping("/removeOrderByOrderId")
    @ApiOperation(value = "用户删除订单")
    public Result removeOrderByOrderId(Integer releaseDynamicId) throws Exception {
        releaseDynamicService.removeOrderByOrderId(releaseDynamicId);
        return Result.ok();
    }

    @GetMapping("/removeOrderByReleaseUserId")
    @ApiOperation(value = "商家删除订单")
    public Result removeOrderByReleaseUserId(Integer releaseDynamicId) throws Exception {
        releaseDynamicService.removeOrderByReleaseUserId(releaseDynamicId);
        return Result.ok();
    }

    @GetMapping("/selectById")
    @ApiOperation(value = "根据id查询信息")
    public Result selectById(Integer releaseDynamicId) throws Exception {
        ReleaseDynamicDto releaseDynamicDto = releaseDynamicService.selectById(releaseDynamicId);
        return Result.ok(releaseDynamicDto);
    }

    @PostMapping("/createPublicationByZfb")
    @ApiOperation(value = "创建发布信息")
    public Result createPublicationByZfb(@RequestBody ReleaseDynamicVo releaseDynamicVo) throws Exception {
        releaseDynamicService.createPublicationByZfb(releaseDynamicVo);
        return Result.ok();
    }

    @PostMapping("/createPublicationByAmount")
    @ApiOperation(value = "创建发布信息")
    public Result createPublicationByAmount(@RequestBody ReleaseDynamicVo releaseDynamicVo) throws Exception {
        releaseDynamicService.createPublicationByAmount(releaseDynamicVo);
        return Result.ok();
    }



}
